function play_v(val, isVip,i) {
  if (isVip == 1) {
    alert(`本歌曲为VIP歌曲，请开通VIP后再播放！`)
    return
  }
  play_video(val)
  $('.play_icon').each((index,item)=>{
    $(item).removeClass('play_icon_cl')
    if(index==i) $(item).addClass('play_icon_cl')
  })
}

//左侧点击事件
async function leftdom(id, index, uptime, update) {
  let lt_dom = $('.rankingList_content_l_t dl')
  lt_dom.each((index, item) => {
    item.classList.remove('rankingList_content_l_t_ct')
  })
  let leftDom = $('.rankingList_content_l_t dl')[index]
  leftDom.classList.add('rankingList_content_l_t_ct')

  list_Detail(id, uptime, update) //获取榜单详情
}
//获取榜单详情
async function list_Detail(id = 19723756, uptime, update) {
  const res = await axios({
    url: `/playlist/detail?id=${id}`,
    method: 'get'
  })
  let result = res.data.playlist
  $('.rcr_top_left img')[0].src = result.coverImgUrl; //榜单大图
  $('.rcr_top_right h3')[0].innerHTML = result.name; //榜单name
  $('.uptime')[0].innerHTML = (new Date(uptime)).toLocaleDateString(); //更新时间
  $('.update')[0].innerHTML = update; //更新频率
  $('.play_num')[0].innerHTML = result.playCount; //播放次数
  $('.rl_share')[0].innerHTML = result.shareCount; //分享次数
  $('.rl_ly')[0].innerHTML = result.commentCount; //留言次数
  $('.rl_file')[0].innerHTML = result.subscribedCount; //收藏次数
  $('.rl_List_title_left_num span').html(result.tracks.length);//搜索结果
  $('.r_tboby')[0].innerHTML = ''; //将tbody内容清空
  (result.tracks).forEach(async function (item, index) {
      $('.r_tboby')[0].innerHTML += `
      <tr class="re_video">
        <th scope="row">${index+1}</th>
        <td class="fx_fs">
            <img class="video_img fl" src="${index<3?item.al.picUrl+'?param=40y40':''}" alt="">
            <div class="play_icon fl" onclick="play_v(${item.id},${item.fee},${index})"></div>
            <span class="fl r_name">${item.name}</span>
        </td>
        <td class="video_detail">
            <div class="video_time">${toMinutes(item.dt)}</div>
            <div class="video_action">
                <img src="../image/plus.svg" alt="">
                <img src="../image/file.svg" alt="">
                <img src="../image/share.svg" alt="">
                <img src="../image/download.svg" alt="">
            </div>
        </td>
        <td class="video_detail_at"><span>${item.ar[0].name}</span></td>
    </tr>
      `
  })
  $('.re_video').each((index, item) => {
    if (index > 2) {
      item.children[1].children[0].remove()
    }
  })
}


searchList() //获取榜单列表
async function searchList() {
  const res = await axios({
    url: `/toplist`,
    method: 'get'
  })
  let result = res.data.list
  result.forEach(async (item, index) => {
    if (index < 4) {
      $('.rankingList_content_l_t')[0].innerHTML += `
                <dl onclick="leftdom(${item.id},${index},${item.updateTime},'${item.updateFrequency}')">
                <dt><img src=${item.coverImgUrl} alt=""></dt>
                <dd>
                    <p class="rl_c_name">${item.name}</p>
                    <p class='rl_c_update'>${item.updateFrequency}</p>
                </dd>
            </dl>
                `
    } else {
      $('.rankingList_content_l_t')[1].innerHTML += `
        <dl onclick="leftdom(${item.id},${index},${item.updateTime},'${item.updateFrequency}')">
        <dt><img src="${item.coverImgUrl}" alt=""></dt>
            <dd>
                <p class="rl_c_name">${item.name}</p>
                <p class='rl_c_update'>${item.updateFrequency}</p>
            </dd>
        </dl>
        `
    }
  })
  $('.rankingList_content_l_t dl')[0].click()
}
